package mx.itesm.goyostacoadventure;

/**
 * Created by OscarG on 07/05/15.
 */
import android.util.Log;

import org.andengine.engine.Engine;
import org.andengine.engine.camera.hud.HUD;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.text.Text;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.opengl.font.IFont;
import org.andengine.opengl.texture.ITexture;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.util.adt.align.HorizontalAlign;
import org.andengine.util.adt.color.Color;

/**
 * Created by Rodrigo on 5/6/2015.
 */
public class EstadoJuego extends HUD{
    private Engine engine;
    private ControlJuego actividad;

    private int vidas;
    private Text txtVidas;
    private final int VIDAS_INICIALES = 3;
    private Rectangle tresVidas;
    private Sprite taco;


    public EstadoJuego(Engine engine, ControlJuego actividad,AdministradorRecursos admRecursos){
        this.engine = engine;
        vidas = VIDAS_INICIALES;
        this.actividad = actividad;

        agregarVidas();

        ITextureRegion regionTaco1 = admRecursos.regionTaco;
        taco = new Sprite(450,ControlJuego.ALTO_CAMARA-20,regionTaco1,admRecursos.vbom);
    }

    private Font crearTipoLetra(){
        // La imagen que contiene cada símbolo
        final ITexture fontTexture = new BitmapTextureAtlas(engine.getTextureManager(),1024,1024);

        // Carga el archivo, tamaño 36, antialias y color
        Font tipoLetra = FontFactory.createFromAsset(engine.getFontManager(),
                fontTexture, actividad.getAssets(),"Texto/GreatLakesShadowNF.ttf", 20, true, 0xFF00FF00);
        tipoLetra.load();
        tipoLetra.prepareLetters("Regrsa lmnupidPd,ck".toCharArray());

        return tipoLetra;
    }

    public void agregarVidas(){
        tresVidas = new Rectangle(400,ControlJuego.ALTO_CAMARA-20,200,100,engine.getVertexBufferObjectManager());
        tresVidas.setColor(Color.TRANSPARENT);
        this.attachChild(tresVidas);

        //Letrero
        IFont tipo = crearTipoLetra();
        txtVidas = new Text(100,50,tipo,"Lifes: " + vidas,30,engine.getVertexBufferObjectManager());
        txtVidas.setColor(Color.BLACK);
        txtVidas.setWidth(200);
        txtVidas.setHorizontalAlign(HorizontalAlign.CENTER);
        tresVidas.attachChild(txtVidas);
        //this.attachChild(taco);


    }

    public void disminuirVidas(int delta){
        vidas -= delta;
        txtVidas.setText("Lifes: " + vidas);
    }

    public int getVidas(){return vidas;}

    public void setVidas(int vidas){
        this.vidas = vidas;

    }

}
